package com.hx.skyDrive.listener;

import java.io.File;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import com.hx.skyDrive.util.StringUtil;
/**
 * 用来创建该项目文件上传的存放目录
 * @author Huathy
 * @date 2020年3月14日
 */
@WebListener
public class InitApplicationListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		// TODO Auto-generated method stub
	}

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		String path = "../files";
		
		String temp = sce.getServletContext().getInitParameter("filesPath");
		
		if( !StringUtil.checkNull(temp) ){
			path = temp;
		}
		
		String basePath  = sce.getServletContext().getRealPath("/");
		File fl = new File(basePath + path);
		if( !fl.exists() ){
			fl.mkdirs();
		}
	}
	
}
